package com.dzl.order;

import com.dzl.base.controller.BaseController;
import com.dzl.enterprise.pojo.dto.WelfareEnterpriseApiOrderSaveDto;
import com.dzl.enterprise.pojo.vo.WelfareEnterpriseApiOrderExpressVo;
import com.dzl.enterprise.pojo.vo.WelfareEnterpriseApiOrderVo;
import com.dzl.enterprise.service.WelfareEnterpriseApiService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单相关API控制层
 * @author liuguanjun
 * @date 2021-11-24 11:48:29
 */
@RestController
@RequestMapping("/order")
public class WelfareOrderController extends BaseController {

    @Autowired
    private WelfareEnterpriseApiService service;

    /**
     * 保存api订单，第三方接口调用
     * @param welfareEnterpriseApiOrderSaveDto 订单保存对象
     * @author liuguanjun
     * @date 2021-11-24 15:47:30
     **/
    @PostMapping("/saveOrder")
    public JsonResult<Integer> saveOrder(@RequestBody WelfareEnterpriseApiOrderSaveDto welfareEnterpriseApiOrderSaveDto) {
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getSkuId())){
            return JsonResult.paramErrWithMsg("skuId不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getGoodsName())){
            return JsonResult.paramErrWithMsg("goodsName商品名称不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getGoodsImg())){
            return JsonResult.paramErrWithMsg("goodsImg商品图片不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getGoodsCode())){
            return JsonResult.paramErrWithMsg("goodsCode商品编码不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getGoodsAttrs())){
            return JsonResult.paramErrWithMsg("goodsAttrs商品规格不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getNum())){
            return JsonResult.paramErrWithMsg("num商品数量不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getAddress())){
            return JsonResult.paramErrWithMsg("address收货地址不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getName())){
            return JsonResult.paramErrWithMsg("name收货人姓名不能传空");
        }
        if(EmptyUtils.isEmpty(welfareEnterpriseApiOrderSaveDto.getPhone())){
            return JsonResult.paramErrWithMsg("phone收货人电话不能传空");
        }
        Integer enterpriseId = getWxUserInfo().getEnterpriseId();
        welfareEnterpriseApiOrderSaveDto.setEnterpriseId(enterpriseId);
        Integer result = service.saveWelfareEnterpriseApiOrder(welfareEnterpriseApiOrderSaveDto);
        return JsonResult.success(result);
    }

    /**
     * 获取api订单详情，第三方接口调用
     * @param orderId 订单id
     * @author liuguanjun
     * @date 2021-11-24 15:48:30
     **/
    @GetMapping("/getOrderDetail")
    public JsonResult<WelfareEnterpriseApiOrderVo> getWelfareEnterpriseApiOrderDetail(Integer orderId) {
        if(EmptyUtils.isEmpty(orderId)){
            return JsonResult.paramErrWithMsg("orderId不能传空");
        }
        WelfareEnterpriseApiOrderVo order = service.getWelfareEnterpriseApiOrderDetail(orderId);
        return JsonResult.success(order);
    }

    /**
     * 订单确认收货，第三方接口调用
     * @param orderId 订单id
     * @author liuguanjun
     * @date 2021-11-26 10:21:30
     **/
    @GetMapping("/confirmReceiptOrder")
    public JsonResult<Integer> confirmReceiptOrder(Integer orderId) {
        if(EmptyUtils.isEmpty(orderId)){
            return JsonResult.paramErrWithMsg("orderId不能传空");
        }
        Integer result = service.confirmReceiptOrder(orderId,getWxUserInfo().getEnterpriseId());
        return JsonResult.success(result);
    }

    /**
     * 订单物流信息查询
     * @date 2021/12/09 14:11
     * @author liuguanjun
     * @param orderId   订单id
     */
    @GetMapping("getOrderExpressInfo")
    public JsonResult<List<WelfareEnterpriseApiOrderExpressVo>> getOrderExpressInfo(Integer orderId) {
        if(EmptyUtils.isEmpty(orderId)) {
            return JsonResult.paramErrWithMsg("orderId不能传空");
        }
        return JsonResult.success(service.getOrderExpressInfo(orderId));
    }
}
